package it.datagraf.formazione.hellostruts.struts;

import it.datagraf.formazione.hellostruts.entity.CurriculumVitae;
import it.datagraf.formazione.hellostruts.form.BeanCurriculumForm;
import it.datagraf.formazione.hellostruts.service.CVserviceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class OwnerInsertCvAction extends Action {

	public static Log log = LogFactory.getLog(OwnerInsertCvAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		BeanCurriculumForm ef = (BeanCurriculumForm) form;

		CVserviceImpl serv = new CVserviceImpl();

		CurriculumVitae cv = ef.getCurriculumVitae();
		log.info("--------------------------------------------------------");
		log.info(request.getParameter("curriculumvitae.nome") + "   == "
				+ ef.getCurriculumVitae().getNome());

		 cv.setNome(cv.getNome());
		 cv.setCognome(cv.getCognome());
		 cv.setSesso(cv.getSesso());
		 cv.setNote(cv.getNote());
		 cv.setFile(cv.getFile());
		 cv.setEta(cv.getEta());
		 cv.setOwner(request.getRemoteUser());

		 serv.insertCV(cv);

		return mapping.findForward("success");
	}
}